/*
 * Copyright 2006 Kevin Wetzels 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0 
 *       
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package be.roam.drest.service.bloglines.xml;

import java.io.IOException;
import java.io.InputStream;

import org.xml.sax.SAXException;

import be.roam.drest.service.bloglines.BloglinesEntryList;
import be.roam.drest.service.bloglines.BloglinesSubscription;
import be.roam.drest.xml.SaxParser;

/**
 * Class that centralizes the parsing of Bloglines response xml.
 */
public class BloglinesXmlParser extends SaxParser {
    
    /**
     * Parses subscriptions.
     * 
     * @param subscriptionsResponse response to a subscriptions call
     * 
     * @return bloglines subscriptions
     * 
     * @throws SAXException
     * @throws IOException
     */
    public static BloglinesSubscription parseSubscriptions(InputStream subscriptionsResponse) throws SAXException, IOException {
        BloglinesSubscriptionsHandler bloglinesSubscriptionsHandler = new BloglinesSubscriptionsHandler();
        parse(subscriptionsResponse, bloglinesSubscriptionsHandler);
        return bloglinesSubscriptionsHandler.getEntry();    
    }
    
    /**
     * Parses items or entries.
     * 
     * @param itemResponse response for the items
     * 
     * @return bloglines entry list
     * 
     * @throws SAXException
     * @throws IOException
     */
    public static BloglinesEntryList parseItem(InputStream itemResponse) throws SAXException, IOException {
        BloglinesEntryList feed = new BloglinesEntryList();
        BloglinesEntriesHandler bloglinesEntriesHandler = new BloglinesEntriesHandler(feed);
        parse(itemResponse, bloglinesEntriesHandler);
        return feed;
    }
    
}
